// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { playerType } from "../../../../script/game/gameType";
import { ccs } from "../../../../script/util/services";
import { WinBase } from "../../../../script/wins/WinBase";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends WinBase {

    player: playerType = null;
    start () {
        this.player = this._args.info;
        this.nodes.name.getComponent(cc.Label).string = this.player.name;
        this.nodes.age.getComponent(cc.Label).string = this.player.age + "";
        this.nodes.edu.getComponent(cc.Label).string = this.player.edu.name;
        this.nodes.health.getComponent(cc.Label).string = this.player.disease.length > 0? "生病": "健康";
        this.nodes.money.getComponent(cc.Label).string =  ccs.gf.getOmitNum(this.player.money);
        ccs.spriteExd.setSprite(this.nodes.icon, ccs.resMgr.getHeadIcon(this.player.sex));

        this.setProgress(this.nodes.life, "lifeTime");
        this.setProgress(this.nodes.power, "power");
        this.setProgress(this.nodes.iq, "iq");
        this.setProgress(this.nodes.eq, "eq");
        this.setProgress(this.nodes.learn, "learn");
        this.setProgress(this.nodes.pressure, "pressure");
        this.setProgress(this.nodes.charm, "charm");
        this.setProgress(this.nodes.friend, "relation");
        this.setWork(this.nodes.work);
    }
    //更新属性
    setProgress(node: cc.Node, key: string) {
        let proNode = node
        let all = 100;
        if(key === 'lifeTime') {
            all = 1200;
        } else if(key == "power") {
            all = 300;
        }else if(key == "relation") {
            // proNode.getComponent(cc.ProgressBar).progress = game.playerMgr.heroInfo["relation"].list.length/100;
            // proNode.getChildByName("charmText").getComponent(cc.Label).string = game.playerMgr.heroInfo["relation"].list.length.toString();
            return;
        }
        proNode.getComponent(cc.ProgressBar).progress = this.player[key]/all;
        proNode.getChildByName("charmText").getComponent(cc.Label).string = parseInt(this.player[key]).toString();
    }
    setWork(node: cc.Node) {
        if(!this.player.work) return ;
        let work = this.player.works.find(val => val.id == this.player.work.id);
        node.getComponent(cc.ProgressBar).progress = work.curExp/work.exp[work.level >= 9? 8: work.level];
        node.getChildByName("charmText").getComponent(cc.Label).string = `${ccs.gf.getOmitNum(work.curExp)}/${ccs.gf.getOmitNum(work.exp[work.level>= 9? 8: work.level])}`;
    }
    
    // update (dt) {}
}
